<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../../utils/vue.js"></script>
    <style type="text/css">
        .list-item {
            display: inline-block;
            margin-right: 10px;
        }
        .list-enter-active,
        .list-leave-active {
            transition: all 3s;
        }
        .list-enter, 
        .list-leave-to {
            opacity: 0;
            transform: translateY(300px);
        }
    </style>
</head>
<body>
    非平滑过渡，元素会瞬间移动到新位置
    <div id="list-demo" class="demo">
        <button @click="add">ADD</button>
        <button @click="remove">REMOVE</button>
        <transition-group name="list" tag="p">
            <span v-for="item in items" v-bind:key="item" class="list-item">
                {{ item }}
            </span>
        </transition-group>
    </div>

    <script>
        new Vue({
            el: "#list-demo",
            data: {
                items: [1, 2, 3, 4, 5, 6, 7, 8, 9],
                nextNum: 10,
            },
            methods: {
                randomIndex: function () {
                    return Math.floor(Math.random() * this.items.length);
                },
                add: function () {
                    this.items.splice(this.randomIndex(), 0, this.nextNum++);
                },
                remove: function () {
                    this.items.splice(this.randomIndex(), 1)
                },
            }
        })
    </script>
</body>
</html>